package demo;

import cn.hutool.json.JSONUtil;
import redis.clients.jedis.Jedis;

class stu{
    private int id;
    private String name;
    private int age;

    @Override
    public String toString() {
        return "stu{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}

public class Test2 {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("hadoop10", 6379);
        jedis.auth("123");

        stu s1 = new stu();
        s1.setId(3);
        s1.setName("张三");
        s1.setAge(25);

        // 将对象转换成json字符串       {"id":3,"name":"张三","age":25}
        String s = JSONUtil.toJsonStr(s1);
        jedis.set("person:"+s1.getId(),s);

//        jedis.hset("person:"+s1.getId(),"username",s1.getName());
//        jedis.hset("person:"+s1.getId(),"age",String.valueOf(s1.getAge()));

        jedis.close();
    }
}
